
'use strict';

const ffi = require('ffi-napi');
const ref = require('ref-napi');

const void_t = ref.types.void;
const void_ptr = ref.refType(void_t);
const start = ref.types.int32;
const size_t = ref.types.size_t;
const ptr_t = process.arch === 'x64' ? ref.types.uint64 : ref.types.uint32;

/**
 * common c functions
 */
module.exports = ffi.Library(
  process.platform === 'win32' ? 'msvcrt' : 'libc', {
    malloc: [void_ptr, [size_t]],
    free: [void_t, [void_ptr]],
    memset:[void_ptr,[ptr_t, start, size_t]],
    memcpy: [void_ptr, [ptr_t, ptr_t, size_t]]
  }
);
